package bases;

/**
 * 测试地图信息.
 *
 * Created by HuiWen Ren on 2016/9/1.
 */

import com.rew.navi.models.GMap;

import static java.lang.Integer.max;
import static java.lang.StrictMath.min;

/**
 * 地图边界点信息.

 *图布	549 * 369

 *边界   左上 22，19    左下 270，19
        右上 22，529   右下 270，529  最下 359，275

 *停车区	A区	左上 52，46  右上 52，120
            左下 151，46 右下 151，120

        B区	左上 52，164  右上 52，237
            左下 151，164 右下 151，237

        C区	左上 52，309  右上 52，383
            左下 151，309 右下 151，383

        D区	左上 52，427  右上 52，504
            左下 151，427 右下 151，504

        E区	左上 92，46  右上 92，120
            左下 252，46 右下 252，120

        F区	左上 92，164  右上 92，237
            左下 252，164 右下 252，237

        G区	左上 92，309  右上 92，383
            左下 252，309 右下 252，383

        H区	左上 92，427  右上 92，504
            左下 252，427 右下 252，504

 *出口	①	22，133/22，146

        ②	22，403/22，418

        ③	166，19/180，19

        ④	166，529/180，529

        ⑤	132，310/147，315

        ⑥	403，316/417，311


 *无关区域	Y 322-359
 */

public class GMapInfo {

    /**
     * 将目标区域设为对应值.
     *
     * @param aimMap 目标地图
     * @param x1     上标
     * @param x2     下标
     * @param y1     左标
     * @param y2     右标
     * @param aimKey 1/0
     */
    private void changeInsidePoint(int[][] aimMap, int x1, int x2,
                                   int y1, int y2, int aimKey) {
        for (int i = min(x1, x2); i <= max(x1, x2); i++) {
            for (int j = min(y1, y2); j <= max(y1, y2); j++) {
                aimMap[j][i] = aimKey;
            }
        }
    }

    public GMap initMap() {
        GMap gmap = new GMap();
        int[][] aimMap = new int[550][370];

        // 全部初始化为1
        for (int i = 0; i < 549; i++) {
            for (int j = 0; j < 369; j++) {
                aimMap[i][j] = 0;
            }
        }

        // 边界处理
        for (int i = 19; i <= 529; i++) {
            for (int j = 22; j <= 270; j++) {
                aimMap[i][j] = 1;
            }
        }

        //斜边处理
        double k1 = (275 - 19) / (359 - 270);
        for (int i = 19; i < 275; i++) {
            for (int j = 270; j < 322; j++) {
                if (j == 270 || i == 19) {
                    continue;
                }
                double k2 = (i - 19) / (j - 270);
                if (k2 > k1) {
                    aimMap[i][j] = 1;
                    aimMap[529 + 19 - i][j] = 1;
                }
            }
        }

        /*
        * 边界   左上 22，19    左下 270，19
                右上 22，529   右下 270，529  最下 359，275
        * */

        changeInsidePoint(aimMap, 52, 151, 46, 120, 0);  // A
        changeInsidePoint(aimMap, 52, 151, 164, 237, 0); // B
        changeInsidePoint(aimMap, 52, 151, 309, 383, 0); // C
        changeInsidePoint(aimMap, 52, 151, 427, 504, 0); // D
        changeInsidePoint(aimMap, 192, 252, 46, 120, 0);  // E
        changeInsidePoint(aimMap, 192, 291, 164, 237, 0); // F
        changeInsidePoint(aimMap, 192, 291, 309, 383, 0); // G
        changeInsidePoint(aimMap, 192, 252, 427, 504, 0); // H

        changeInsidePoint(aimMap, 0, 22, 133, 146, 1);    // ①
        changeInsidePoint(aimMap, 0, 22, 403, 418, 1);    // ②
        changeInsidePoint(aimMap, 166, 180, 0, 19, 1);    // ③
        changeInsidePoint(aimMap, 166, 180, 529, 549, 1); // ④

        changeInsidePoint(aimMap, 310, 315, 132, 147, 1);  // ⑤
        changeInsidePoint(aimMap, 310, 315, 403, 417, 1);  // ⑥

        gmap.setMapInfo(aimMap);

        return gmap;
    }
}


/*

                      1：10

          1：道路  7：出口  4：无关区域
          （仅供区分，原代码运行只有0/1）

0000000000000070000000000000000000000000070000000000000
0000000000000070000000000000000000000000070000000000000
0000000000000070000000000000000000000000070000000000000
0000000000000070000000000000000000000000070000000000000
0011111111111111111111111111111111111111111111111111100
0011111111111111111111111111111111111111111111111111100
0011111111111111111111111111111111111111111111111111100
0011111111111111111111111111111111111111111111111111100
0011111111111111111111111111111111111111111111111111100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011111111111111111111111111111111111111111111111111100
0011111111111111111111111111111111111111111111111111100
7711111111111111111111111111111111111111111111111111177
7711111111111111111111111111111111111111111111111111177
7711111111111111111111111111111111111111111111111111177
0011111111111111111111111111111111111111111111111111100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011100000000111100000001111111000000001111000000001100
0011111111111111100000001111111000000001111111111111100
0011111111111111100000001111111000000001111111111111100
0011111111111111100000001111111000000001111111111111100
0000111111111111100000001111111000000001111111111111000
0000001111111111100000001111111000000001111111111100000
0000000011111111100000001111111000000001111111110000000
0000000000111111111111111111111111111111111111000000000
0000000000011111111111111111111111111111111100000000000
0000000000000111111111111111111111111111111000000000000
0000000000000071111111111111111111111111170000000000000
0000000000000000011111111111111111111110000000000000000
0000000000000000000444444444444444444000000000000000000
0000000000000000000044444444444444400000000000000000000
0000000000000000000000444444444444000000000000000000000
0000000000000000000000004444444400000000000000000000000
0000000000000000000000000044440000000000000000000000000
0000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000

 */